<template>
  <li @mouseenter="isEnter=true" @mouseleave="isEnter=false" :class="isEnter? 'active':''">
    <label>
      <input type="checkbox" :checked="checked" @change="todoChecked(id,$event)"/>
      <span>{{todoName}}</span>
    </label>
    <button
        class="btn btn-danger"
        :style="{display:isEnter? 'block':'none'}"
        @click="deleteTodo(id)"
    >删除</button>
  </li>
</template>

<script lang="ts">
export default {
  name: "Item"
}
</script>
<script lang="ts" setup>
import {ref} from "vue";
defineProps<{
  id:string,
  todoName:string,
  checked:boolean,
  deleteTodo:Function,
  todoChecked:Function
}>()
//移入移出
const isEnter = ref(false)
</script>

<style scoped>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

.active{
  background-color: #ccc;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>